import java.util.Arrays;

public class ArrTest {

    public static void main(String[] args) {
        ArrTest test = new ArrTest();



    }
    //找三个连续的奇数
    public static boolean findThreeJS(int[] arr){
        int len = arr.length;
        int i = 0;
        while (i < len - 2){
            if (arr[i] % 2 == 1 && arr[i+2] % 2 == 1){
                if (arr[i+1] % 2 == 1){
                    return true;
                }else {
                    i += 2;
                }
            }else {
                i = i + 1;
            }
        }
        return false;
    }
    //寻找数组中的超过n/2的元素
    public static int findMoreNum(int[] arr){
        Arrays.sort(arr);
        int i =0;
        while (i < arr.length/2){
            //如果当前元素加上一半长度后的元素相等返回arr[i]
            if ((arr[i] == arr[i+(arr.length/2)]) && (i+(arr.length/2) < (arr.length -1))) {
                return arr[i];
            }else {
                while (arr[i] == arr[i+1]){
                    i++;
                }
            }
            i++;
        }
        return arr[i];
    }
    public static int findOnlyOne(int[] arr){
        int temp = 0;
        for (int i = 0; i < arr.length; i++) {
            temp = temp ^ arr[i];
        }
        return temp;
    }
    public static int[] twoSum(int[] arr,int target){
        //将数组有序
        int left = 0;
        int right = arr.length - 1;
        while (left < right){
            if (arr[left] + arr[right] > target && left < right){
                right--;
            }
           if (arr[left] + arr[right] < target && left < right){
                left++;
            }
           if (arr[left] + arr[right] == target){
               return new int[]{left,right};
           }
        }
        return null;
    }
    public static void ArrToString(int[] arr){
        String str = "[";
        for (int i = 0; i < arr.length; i++) {
            str += arr[i];
            if (i == arr.length - 1){
                str += "]";
            }else {
                str += ", ";
            }

        }
        System.out.println(str);
    }
    public static int binarySort(int[] arr,int target,int left,int right){
        int mid = (left + right)/2;
        if (arr[mid] < target){
            return binarySort(arr,target,mid+1,right);
        }else if (arr[mid] == target){
            return mid;
        }else {
            return binarySort(arr,target,left,mid-1);
        }
    }
    public static void isSort(int[] arr){
        boolean flag = false;
        for (int i = 0; i < arr.length - 1; i++) {
            if (arr[i] > arr[i+1]){
                flag = true;
            }
        }
        if (flag){
            System.out.println("数组无序");
        }else {
            System.out.println("数组有序");
        }
    }
    public static void sort(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            boolean flag = false;
            for (int j = 0; j < arr.length -1 - i; j++) {
                if (arr[j] > arr[j+1]){
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
          if (flag){
                break;
           }
        }
    }
    public static int sumArr(int[] arr){
        int sum = 0;
        for (int i:
             arr) {
            sum += i;
        }
        return sum;
    }
    public static double aveArr(int[] arr){
        int sum = 0;
        double avg = 0;
        for (int i:
                arr) {
            sum += i;
        }
        avg = sum/arr.length;
        return avg;
    }
}
